<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<div id="dialog-message_homeWork">
<button id="id-btn-dialogaddjuan" class="btn btn-sm btn-primary">前去增加卷</button>
<table class="table table-striped table-hover table-bordered">
		  <thead>
			<tr id="sys_sys_TestPaper_table_title">
			  <th  width="50">编号</th>   
			  <th  width="20" fname="sys_TestPaperNameCheckBox"><input id="sys_TestPaperNameCheckBox" type="checkbox"></th>
			  <th  width="60" fname="name">卷名称</th> 
			  <th  width="60" fname="note">卷描述</th> 
			  <th  width="60" fname="type">卷类型</th> 
			  <th  width="60" fname="showStartTime">开始时间</th> 
			  <th  width="100" fname="showEndTime">结束时间</th> 
			</tr>
		  </thead>
		  <tbody id="sys_sys_TestPaper_table">
			 
		  </tbody>
</table> 
<ul class="pagination" style ="margin:0 auto;"id="sys_TestPaper_pagination">
					  
</ul>
</div>
<script>
(function(){
	//用户搜索
	function loadTestPaper(event,data){
		if(typeof(data)=="undefined"){
			data={};
		}
		var url ="${pageContext.request.contextPath}/edu/sys_TestPaperAction.do?method=getTestPaper";
		data.name=$("#serch_text").val(); 
		var cp =$("#sys_TestPaper_pagination").find(".active");
		data.start=1;
		data.limit=10;
		if(cp.length>0){
			var ccp=$(cp[0]).text();
			if(parseInt(ccp)){
				data.start=ccp;
			}
		}  
		$("#table_TestPaper").wgrid({
					table_title:"sys_sys_TestPaper_table_title",
					tbodyId:"sys_sys_TestPaper_table",
					pagination:"sys_TestPaper_pagination",
					url:url,
					checkbox:true,
					data:data,
					success:function(){
						changeTestType();
						changeUserState(); 
						if($("#sys_sys_TestPaper_table").children().length<=0){
							$("#dialog-message_homeWork").html("没有卷可以布置！<a id='addjuanlreant' href='javascript:;'>前去增加卷</a>");
							$("#addjuanlreant").click(function(){
								$("#learnPlantAdd_ClassWindow").dialog('destroy'); 
								$("#learnPlantAdd_ClassWindow").html("");
								$("#dialog-message").dialog('destroy'); 
								$("#user_include").html(""); 
								$("#indexContent").load("${pageContext.request.contextPath}/homeWork.jsp?r="+Math.random(),{},function(){
									
								}); 
							});
						}
					}
		});
	};
	$("#id-btn-dialogaddjuan").click(function(){
		$("#learnPlantAdd_ClassWindow").dialog('destroy'); 
		$("#learnPlantAdd_ClassWindow").html("");
		$("#dialog-message").dialog('destroy'); 
		$("#user_include").html(""); 
		$("#indexContent").load("${pageContext.request.contextPath}/homeWork.jsp?r="+Math.random(),{},function(){
			
		}); 
	});
	 //改变头像 和性别，还有类型
	function changeTestType(){ 
		
		var allstate =$("div[name='sys_sys_TestPaper_table_type_tr_td']");
		for(var i=0;i<allstate.length;i++){
			var bc = $(allstate[i]);
			if(bc.text()==1){
				bc.html('<font color="green">固定时间</font>');
			}else if(bc.text()==0){
				bc.html('<font color="red">规定时间</font>');
			}
		}
		
	};
	//改变他的启用禁用的状态
	function changeUserState(){ 
		$("#sys_sys_TestPaper_table").children().click(function(){
			 var allc =$("[name=sys_sys_TestPaper_table_checkbox]");
			 if(allc.length>0){
				 for(var i=0;i<allc.length;i++){
					 $(allc[i])[0].checked =false;
				 }
			 }
			if($(this).find("[name=sys_sys_TestPaper_table_checkbox]")[0].checked==true){
				$(this).find("[name=sys_sys_TestPaper_table_checkbox]")[0].checked=false;
			}else{
				$(this).find("[name=sys_sys_TestPaper_table_checkbox]")[0].checked=true;
				var table_id =$(this).attr("id");
				 
			}
		});
	};
	
	//创建课程和作业的关联
	function createHomeWorkLearnPlant(contrl){
		 
		//拿到当前的卷
		var allc1 =$("input[type=checkbox][name=sys_sys_TestPaper_table_checkbox]:checked");
		if(allc1.length>1||allc1.length<=0){
			alert("没有选中卷");
			return;
		}
		var table_id1=$(allc1[0]).parent().parent().attr("id"); 
		var cdata =$("#"+table_id1).data(table_id1);
		//alert(obj2str(cdata));
	    $("#addPlanrt_juan").parent().prev().text(cdata.name);
		$("#addPlanrt_juan").data("testpaper",cdata);
		$(contrl).dialog('destroy'); 
	     $("#learnPlantAdd_ClassWindow").html("");
		/*
		$.ajax({
			type: "POST",
			url:"${pageContext.request.contextPath}/edu/sys_LearnPlantAction.do?method=updateLearnPlantHomeWork",
			data:{table_id:table_id,juanId:table_id1},
			dataType:'json',
			success: function(msg){
				alert(msg.message); 
				$(contrl).dialog('destroy'); 
				$("#user_include").html("");
				//loadTestPaper(null,{});
			}
		});*/ 
	};
	//加载
	$(function(){ 
		loadTestPaper(null,{});
	});
	window.learnPlant_homeWork={};
	window.learnPlant_homeWork.createHomeWorkLearnPlant=createHomeWorkLearnPlant;
	
})();
</script>